package com.jiulan.hearthearing.ui.course.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jiulan.hearthearing.R;
import com.jiulan.hearthearing.ui.course.model.CourseDetailsModel;

import java.util.List;

public class CourseFMMuluDialogAdapter extends BaseQuickAdapter<CourseDetailsModel.DataBean.ClassListBean, BaseViewHolder> {
    private int clickId = -1;
    private boolean isPlaying = false;

    //进入单选页面执行这个方法，选中传过来的ID对应的item
    public void setClickPosition(int clickId, boolean isPlaying) {
        this.clickId = clickId;
        this.isPlaying = isPlaying;
    }

    public CourseFMMuluDialogAdapter(List<CourseDetailsModel.DataBean.ClassListBean> data) {
        super(R.layout.item_course_fm_mulu_dialog, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CourseDetailsModel.DataBean.ClassListBean item) {
        if (clickId == item.getId()) {
            helper.setTextColor(R.id.tvTitle, mContext.getResources().getColor(R.color.title_bg));
            helper.setGone(R.id.ivIsPlaying, true);
            if (isPlaying) {
                helper.setImageResource(R.id.ivPlay, R.mipmap.course_pause_gray);
            } else {
                helper.setImageResource(R.id.ivPlay, R.mipmap.course_play_gray);
            }
        } else {
            helper.setTextColor(R.id.tvTitle, mContext.getResources().getColor(R.color.black_light));
            helper.setGone(R.id.ivIsPlaying, false);
            helper.setImageResource(R.id.ivPlay, R.mipmap.course_play_gray);
        }
        switch (item.getIs_free()) {
            case 0://收费
                helper.setGone(R.id.ivPay, true);
                break;
            case 1://免费
                helper.setGone(R.id.ivPay, false);
                break;
        }
        helper.setText(R.id.tvTitle, item.getName());
        helper.addOnClickListener(R.id.ivPlay);

    }
}
